package easy;

import java.util.*;

/**
 * 705. 设计哈希集合
 * 创建时间：2024-04-15 00:15
 * 地址：https://leetcode.cn/problems/design-hashset/description/
 */
public class 设计哈希集合_705 {
    class MyHashSet {
        private static final int BASE = 769;
        LinkedList<Integer>[] set;

        public int hash(int key) {
            return key % BASE;
        }

        public MyHashSet() {
            set = new LinkedList[BASE];
            Arrays.fill(set, new LinkedList<Integer>());
        }

        public void add(int key) {
            int index = hash(key);
            LinkedList<Integer> linkedList = set[index];
            for (Integer next : linkedList) {
                if (next == key) {
                    return;
                }
            }
            linkedList.addLast(key);
        }

        public void remove(int key) {
            int index = hash(key);
            LinkedList<Integer> linkedList = set[index];
            for (Integer next : linkedList) {
                if (next == key) {
                    linkedList.remove(Integer.valueOf(key));
                    return;
                }
            }
        }

        public boolean contains(int key) {
            int index = hash(key);
            LinkedList<Integer> linkedList = set[index];
            for (Integer next : linkedList) {
                if (next == key) {
                    return true;
                }
            }
            return false;
        }
    }

    public static void main(String[] args) {
        List<Integer> l = new ArrayList<>();
        l.add(1);
        l.add(2);
        l.add(1);
        l.add(4);
        l.removeIf(r -> r % 2 == 0);
        System.out.println(l);
    }
}
